
import java.sql.*;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Hermit
 */
public class TablaProveedor extends javax.swing.JFrame {
Funciones f=new Funciones();
DefaultTableModel dt=new DefaultTableModel();
Connection conn;
ResultSet rs;
Statement stmt;
int AoM=0;//AoM=Agregar o Modificar: variable que controla si se agrega o modifica en el jDialog Agregar=0,Modificar=1
int contClic=0;//Controla los textfield de los telefonos extra
int cambioTF=1; //Controla la busqueda del tfBuscar para proveedores activos y desactivados
    
    /**
     * Creates new form TablaProveedor
     */
    public TablaProveedor() {
        initComponents();
        dt.addColumn("Código");
        dt.addColumn("Nombre");
        dt.addColumn("Dirección");
        dt.addColumn("Teléfono");
        
        tablaProveedores.setModel(dt);
        tablaProveedores.removeColumn(tablaProveedores.getColumn(0));
        btnDarAlta.setVisible(false);
        btnAtras.setVisible(false);
        String sql="SELECT * FROM proveedores,tel_proveedor where proveedores.codProveedor=tel_proveedor.codProveedor and activo=1"; 
        mostrarTabla(sql);
        estadoTelefono();
    }
    
     public void estadoTelefono(){
        l1.setVisible(false);
        l2.setVisible(false);
        l3.setVisible(false);
        l4.setVisible(false);
        l5.setVisible(false);
        tfTel1.setVisible(false);
        tfTel2.setVisible(false);
        tfTel3.setVisible(false);
        tfTel4.setVisible(false);
        tfTel5.setVisible(false);
    }
    
     public void mostrarTabla(String sql){
        conn=Conexion.obtenerConexion();
        dt.setRowCount(0);
        try {
            stmt=conn.createStatement();
            rs=stmt.executeQuery(sql);
            while(rs.next()){
                dt.addRow(new Object[]{rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(6)});
            }
            conn.close();
        } catch (SQLException ex) {
           JOptionPane.showMessageDialog(null, "Error al mostrar tabla "+ex,"ERROR",JOptionPane.ERROR_MESSAGE);
        }
    }
     
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jdAccion = new javax.swing.JDialog();
        panelRect4 = new org.edisoncor.gui.panel.PanelRect();
        lblTitulo = new org.edisoncor.gui.label.LabelMetric();
        panelRect5 = new org.edisoncor.gui.panel.PanelRect();
        panelCurves2 = new org.edisoncor.gui.panel.PanelCurves();
        btnGuardar = new org.edisoncor.gui.button.ButtonIpod();
        btnLimpiar = new org.edisoncor.gui.button.ButtonIpod();
        btnCancelar = new org.edisoncor.gui.button.ButtonIpod();
        panelRound1 = new org.edisoncor.gui.panel.PanelRound();
        labelMetric2 = new org.edisoncor.gui.label.LabelMetric();
        tfNom = new org.edisoncor.gui.textField.TextFieldRectBackground();
        tfDir = new org.edisoncor.gui.textField.TextFieldRectBackground();
        labelMetric4 = new org.edisoncor.gui.label.LabelMetric();
        labelMetric5 = new org.edisoncor.gui.label.LabelMetric();
        l1 = new org.edisoncor.gui.label.LabelMetric();
        l2 = new org.edisoncor.gui.label.LabelMetric();
        l3 = new org.edisoncor.gui.label.LabelMetric();
        l4 = new org.edisoncor.gui.label.LabelMetric();
        l5 = new org.edisoncor.gui.label.LabelMetric();
        btnAdd = new org.edisoncor.gui.button.ButtonIcon();
        btnElim = new org.edisoncor.gui.button.ButtonIcon();
        tfTel = new javax.swing.JFormattedTextField();
        tfTel1 = new javax.swing.JFormattedTextField();
        tfTel2 = new javax.swing.JFormattedTextField();
        tfTel3 = new javax.swing.JFormattedTextField();
        tfTel4 = new javax.swing.JFormattedTextField();
        tfTel5 = new javax.swing.JFormattedTextField();
        panelRect1 = new org.edisoncor.gui.panel.PanelRect();
        labelMetric1 = new org.edisoncor.gui.label.LabelMetric();
        panelRect2 = new org.edisoncor.gui.panel.PanelRect();
        panelCurves1 = new org.edisoncor.gui.panel.PanelCurves();
        btnNuevo = new org.edisoncor.gui.button.ButtonIpod();
        btnModificar = new org.edisoncor.gui.button.ButtonIpod();
        btnVerBajas = new org.edisoncor.gui.button.ButtonIpod();
        btnDarBaja = new org.edisoncor.gui.button.ButtonIpod();
        panelRect3 = new org.edisoncor.gui.panel.PanelRect();
        tfBuscar = new java.awt.TextField();
        labelMetric3 = new org.edisoncor.gui.label.LabelMetric();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaProveedores = new org.jdesktop.swingx.JXTable();
        btnDarAlta = new org.edisoncor.gui.button.ButtonIpod();
        btnAtras = new org.edisoncor.gui.button.ButtonIpod();

        lblTitulo.setText("XD");
        panelRect4.add(lblTitulo);

        jdAccion.getContentPane().add(panelRect4, java.awt.BorderLayout.PAGE_START);

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/guardar.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/limpiar.png"))); // NOI18N
        btnLimpiar.setText("Limpiar");
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/cancel.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelCurves2Layout = new javax.swing.GroupLayout(panelCurves2);
        panelCurves2.setLayout(panelCurves2Layout);
        panelCurves2Layout.setHorizontalGroup(
            panelCurves2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCurves2Layout.createSequentialGroup()
                .addGap(126, 126, 126)
                .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(189, Short.MAX_VALUE))
        );
        panelCurves2Layout.setVerticalGroup(
            panelCurves2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCurves2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelCurves2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        labelMetric2.setText("Nombre:");

        labelMetric4.setText("Dirección:");

        labelMetric5.setText("Teléfono:");

        l1.setText("Teléfono:");

        l2.setText("Teléfono:");

        l3.setText("Teléfono:");

        l4.setText("Teléfono:");

        l5.setText("Teléfono:");

        btnAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/add.png"))); // NOI18N
        btnAdd.setText("buttonIcon1");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        btnElim.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/cancel.png"))); // NOI18N
        btnElim.setText("buttonIcon1");
        btnElim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnElimActionPerformed(evt);
            }
        });

        try {
            tfTel.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            tfTel1.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            tfTel2.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            tfTel3.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            tfTel4.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            tfTel5.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        javax.swing.GroupLayout panelRound1Layout = new javax.swing.GroupLayout(panelRound1);
        panelRound1.setLayout(panelRound1Layout);
        panelRound1Layout.setHorizontalGroup(
            panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelRound1Layout.createSequentialGroup()
                .addContainerGap(21, Short.MAX_VALUE)
                .addGroup(panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelRound1Layout.createSequentialGroup()
                        .addGroup(panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelMetric4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelMetric2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tfDir, javax.swing.GroupLayout.PREFERRED_SIZE, 408, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tfNom, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(panelRound1Layout.createSequentialGroup()
                        .addComponent(l4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(tfTel4, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelRound1Layout.createSequentialGroup()
                        .addComponent(l5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(tfTel5, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelRound1Layout.createSequentialGroup()
                        .addComponent(l3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(tfTel3, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelRound1Layout.createSequentialGroup()
                        .addComponent(l2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(tfTel2, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelRound1Layout.createSequentialGroup()
                        .addComponent(l1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(tfTel1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelRound1Layout.createSequentialGroup()
                        .addComponent(labelMetric5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(tfTel, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnElim, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        panelRound1Layout.setVerticalGroup(
            panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRound1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(labelMetric2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfNom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelMetric4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfDir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelMetric5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 21, Short.MAX_VALUE)
                    .addComponent(btnElim, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfTel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(l1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfTel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfTel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfTel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(l5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfTel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout panelRect5Layout = new javax.swing.GroupLayout(panelRect5);
        panelRect5.setLayout(panelRect5Layout);
        panelRect5Layout.setHorizontalGroup(
            panelRect5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect5Layout.createSequentialGroup()
                .addGroup(panelRect5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelRect5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(panelCurves2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(panelRect5Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(panelRound1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelRect5Layout.setVerticalGroup(
            panelRect5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelRect5Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(panelRound1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(panelCurves2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21))
        );

        jdAccion.getContentPane().add(panelRect5, java.awt.BorderLayout.CENTER);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        panelRect1.setColorPrimario(new java.awt.Color(0, 204, 204));

        labelMetric1.setText("PROVEEDORES");
        labelMetric1.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        panelRect1.add(labelMetric1);

        getContentPane().add(panelRect1, java.awt.BorderLayout.PAGE_START);

        panelRect2.setColorPrimario(new java.awt.Color(0, 102, 204));
        panelRect2.setColorSecundario(new java.awt.Color(0, 204, 204));

        panelCurves1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/add.png"))); // NOI18N
        btnNuevo.setText("Nuevo");
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });
        panelCurves1.add(btnNuevo, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 0, 60, 60));

        btnModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/preferences-composer.png"))); // NOI18N
        btnModificar.setText("Modificar");
        btnModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarActionPerformed(evt);
            }
        });
        panelCurves1.add(btnModificar, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 0, 70, 60));

        btnVerBajas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/ver.png"))); // NOI18N
        btnVerBajas.setText("Ver Bajas");
        btnVerBajas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVerBajasActionPerformed(evt);
            }
        });
        panelCurves1.add(btnVerBajas, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, -10, 70, 70));

        btnDarBaja.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/bajas.png"))); // NOI18N
        btnDarBaja.setText("Dar Baja");
        btnDarBaja.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDarBajaActionPerformed(evt);
            }
        });
        panelCurves1.add(btnDarBaja, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, -10, 70, 70));

        panelRect3.setColorPrimario(new java.awt.Color(0, 51, 204));
        panelRect3.setColorSecundario(new java.awt.Color(0, 153, 153));

        tfBuscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tfBuscarKeyReleased(evt);
            }
        });

        labelMetric3.setText("Buscar");

        tablaProveedores.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tablaProveedores);

        btnDarAlta.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/altas.png"))); // NOI18N
        btnDarAlta.setText("Dar Alta");
        btnDarAlta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDarAltaActionPerformed(evt);
            }
        });

        btnAtras.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/cancelar.png"))); // NOI18N
        btnAtras.setText("Atrás");
        btnAtras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAtrasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelRect3Layout = new javax.swing.GroupLayout(panelRect3);
        panelRect3.setLayout(panelRect3Layout);
        panelRect3Layout.setHorizontalGroup(
            panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect3Layout.createSequentialGroup()
                .addGroup(panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(panelRect3Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnAtras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDarAlta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(panelRect3Layout.createSequentialGroup()
                            .addGap(124, 124, 124)
                            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 428, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(panelRect3Layout.createSequentialGroup()
                            .addGap(205, 205, 205)
                            .addComponent(labelMetric3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(26, 26, 26)
                            .addComponent(tfBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(panelRect3Layout.createSequentialGroup()
                            .addGap(25, 25, 25)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 593, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(38, Short.MAX_VALUE))
        );
        panelRect3Layout.setVerticalGroup(
            panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect3Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelMetric3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnDarAlta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAtras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout panelRect2Layout = new javax.swing.GroupLayout(panelRect2);
        panelRect2.setLayout(panelRect2Layout);
        panelRect2Layout.setHorizontalGroup(
            panelRect2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect2Layout.createSequentialGroup()
                .addGroup(panelRect2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelCurves1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(panelRect2Layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(panelRect3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelRect2Layout.setVerticalGroup(
            panelRect2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelRect2Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(panelRect3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(panelCurves1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        getContentPane().add(panelRect2, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
        // TODO add your handling code here:
        AoM=0;
        contClic=0;
        //lblTitulo2.setText("Agregar Usuario");
       
        tfDir.setText("");
        tfNom.setText("");
        tfTel.setText("");
        
        tfTel1.setText("");
        l1.setVisible(false);
        tfTel1.setVisible(false);
        tfTel2.setText("");
        l2.setVisible(false);
        tfTel2.setVisible(false);
        tfTel3.setText("");
        l3.setVisible(false);
        tfTel3.setVisible(false);
        tfTel4.setText("");
        l4.setVisible(false);
        tfTel4.setVisible(false);
        tfTel5.setText("");
        l5.setVisible(false);
        tfTel5.setVisible(false);
       jdAccion.pack();   
       jdAccion.setLocationRelativeTo(null);
       jdAccion.setVisible(true);

    }//GEN-LAST:event_btnNuevoActionPerformed

    private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarActionPerformed
        // TODO add your handling code here:
      AoM=1;
        //lblTitulo2.setText("Modificar Datos de Usuario");
        try{
            int codigo=Integer.parseInt(dt.getValueAt(tablaProveedores.getSelectedRow(), 0).toString());//Obtengo la codigo de la fila seleecionada
            String sql="SELECT * FROM proveedores WHERE codProveedor='"+codigo+"'";
            
            conn=Conexion.obtenerConexion();
            try {
                stmt=conn.createStatement();
                rs=stmt.executeQuery(sql);
                while(rs.next()){
                    tfNom.setText(rs.getString(2));
                    tfDir.setText(rs.getString(3));
                    
                }
                ////////////////MOSTRAR TELEFONOS SEGUN EL NUMERO DE TELEFONOS GUADADOS
                String sql2="SELECT * FROM tel_proveedor WHERE codProveedor='"+codigo+"'";
                rs=stmt.executeQuery(sql2);
                int x;//sirve para saber cuantos telefonos hay por cada usuario en la BD
                while(rs.next()){
                      x=rs.getRow();
                      if(x==1){
                          tfTel.setText(rs.getString(2));
                          l1.setVisible(false);
                          tfTel1.setVisible(false);
                          l2.setVisible(false);
                          tfTel2.setVisible(false);
                          l3.setVisible(false);
                          tfTel3.setVisible(false);
                          l4.setVisible(false);
                          tfTel4.setVisible(false);
                          l5.setVisible(false);
                          tfTel5.setVisible(false);
                          contClic=1;
                      }
                      if(x==2){
                          tfTel1.setText(rs.getString(2));
                          l1.setVisible(true);
                          tfTel1.setVisible(true);
                          contClic=2;
                      }
                      if(x==3){
                          tfTel2.setText(rs.getString(2));
                          l2.setVisible(true);
                          tfTel2.setVisible(true);
                          contClic=3;
                      }
                      if(x==4){
                          tfTel3.setText(rs.getString(2));
                          l3.setVisible(true);
                          tfTel3.setVisible(true);
                          contClic=4;
                      }
                      if(x==5){
                          tfTel4.setText(rs.getString(2));
                          l4.setVisible(true);
                          tfTel4.setVisible(true);
                          contClic=5;
                      }
                      if(x==6){
                          tfTel5.setText(rs.getString(2));
                          l5.setVisible(true);
                          tfTel5.setVisible(true);
                          contClic=6;
                      }
                }
                
                conn.close();
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, "Error al buscar: "+ex);
            }
        
        
        jdAccion.pack();
        jdAccion.setLocationRelativeTo(null);
        jdAccion.setVisible(true);
        }catch(ArrayIndexOutOfBoundsException e){
            JOptionPane.showMessageDialog(null, "Debe elegir un proveedor");
        }
        
    }//GEN-LAST:event_btnModificarActionPerformed

    private void btnVerBajasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVerBajasActionPerformed
        // TODO add your handling code here:
        cambioTF = 0;

        btnDarAlta.setVisible(true);
        btnAtras.setVisible(true);
        
        mostrarTabla("SELECT * FROM proveedores,tel_proveedor where proveedores.codProveedor=tel_proveedor.codProveedor and activo=0");
        btnModificar.setEnabled(false);
        btnDarBaja.setEnabled(false);
        btnNuevo.setEnabled(false);
    }//GEN-LAST:event_btnVerBajasActionPerformed

    private void btnDarBajaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDarBajaActionPerformed
        // TODO add your handling code here:
        darBaja();

    }//GEN-LAST:event_btnDarBajaActionPerformed

    private void tfBuscarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfBuscarKeyReleased
        // TODO add your handling code here:
        String nombre = tfBuscar.getText();
        String sql;
        if (cambioTF == 1) {
            sql = "SELECT * FROM proveedores,tel_proveedor where nombre like '%" + nombre + "%' && (activo=1 && proveedores.codProveedor=tel_proveedor.codProveedor)";
        } else {
            sql = "SELECT * FROM proveedores,tel_proveedor where nombre like '%" + nombre + "%' && (activo=0 && proveedores.codProveedor=tel_proveedor.codProveedor)";
        }

        mostrarTabla(sql);
    }//GEN-LAST:event_tfBuscarKeyReleased

    private void btnDarAltaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDarAltaActionPerformed
        // TODO add your handling code here:
        darAlta();
    }//GEN-LAST:event_btnDarAltaActionPerformed

    private void btnAtrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAtrasActionPerformed
        // TODO add your handling code here:
        cambioTF = 1;
        mostrarTabla("SELECT * FROM proveedores,tel_proveedor where proveedores.codProveedor=tel_proveedor.codProveedor and activo=1");
        btnDarAlta.setVisible(false);
        btnAtras.setVisible(false);
        btnModificar.setEnabled(true);
        btnDarBaja.setEnabled(true);
        btnNuevo.setEnabled(true);
    }//GEN-LAST:event_btnAtrasActionPerformed

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        // TODO add your handling code here:
        contClic++;

        if (contClic == 1) {
            l1.setVisible(true);
            tfTel1.setVisible(true);
        }
        if (contClic == 2) {
            l2.setVisible(true);
            tfTel2.setVisible(true);
        }
        if (contClic == 3) {
            l3.setVisible(true);
            tfTel3.setVisible(true);
        }
        if (contClic == 4) {
            l4.setVisible(true);
            tfTel4.setVisible(true);
        }
        if (contClic == 5) {
            l5.setVisible(true);
            tfTel5.setVisible(true);
        }
        if (contClic > 5) {
            contClic = 5;
        }
    }//GEN-LAST:event_btnAddActionPerformed

    private void btnElimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnElimActionPerformed
        // TODO add your handling code here:
        
      
        if (contClic == 1) {
            l1.setVisible(false);
            tfTel1.setText("");
            tfTel1.setVisible(false);
        }
        if (contClic == 2) {
            l2.setVisible(false);
            tfTel2.setText("");
            tfTel2.setVisible(false);
        }
        if (contClic == 3) {
            l3.setVisible(false);
            tfTel3.setText("");
            tfTel3.setVisible(false);
        }
        if (contClic == 4) {
            l4.setVisible(false);
            tfTel4.setText("");
            tfTel4.setVisible(false);
        }
        if (contClic == 5) {
            l5.setVisible(false);
            tfTel5.setText("");
            tfTel5.setVisible(false);
        }
        if (contClic < 1) {
            contClic = 1;
        }
        contClic--;
    }//GEN-LAST:event_btnElimActionPerformed

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here:
        if(AoM==0){//AoM=0: Funcion Agregar
            String sql;
            String nom=tfNom.getText();
            String dir=tfDir.getText();
            String tel=tfTel.getText();

            Boolean tel1=tfTel1.isVisible()&&tfTel1.getText().equals("    -    ");
            Boolean tel2=tfTel2.isVisible()&&tfTel2.getText().equals("    -    ");
            Boolean tel3=tfTel3.isVisible()&&tfTel3.getText().equals("    -    ");
            Boolean tel4=tfTel4.isVisible()&&tfTel4.getText().equals("    -    ");
            Boolean tel5=tfTel5.isVisible()&&tfTel5.getText().equals("    -    ");

            if(nom.equals("")||tel.equals("")||dir.equals("")||tel.equals("    -    ") ||tel1||tel2||tel3||tel4||tel5){
                JOptionPane.showMessageDialog(null, "No deje campos vacíos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
            }else{

                
                sql="INSERT INTO proveedores(nombre,direccion,activo) VALUES('"+nom+"','"+dir+"','1')";
                f.insertar(sql);
                /////Obtengo el codigo del proveedor ingresado para guardar su telefono
                String codigo="SELECT * FROM proveedores";
                ResultSet rs = f.buscar(codigo);
                int cod = 0;
                try {
                    rs.last();
                    cod=rs.getInt(1);
                    //JOptionPane.showMessageDialog(null, cod);
                } catch (SQLException ex) {
                    JOptionPane.showMessageDialog(null, ex);
                }
                f.cerrarConexion();
                String sql2="INSERT INTO tel_proveedor VALUES('"+cod+"','"+tel+"')";
                f.insertar(sql2);
                
                insertarTelExtra(cod);
              
                mostrarTabla("SELECT * FROM proveedores,tel_proveedor where proveedores.codProveedor=tel_proveedor.codProveedor and activo=1");
                jdAccion.dispose();
            }
             
        }else{//AoM=1: Funcion Modificar
            String nombre, primer, segundo, dir;
            nombre = tfNom.getText();
            dir = tfDir.getText();
            int codigo = Integer.parseInt(dt.getValueAt(tablaProveedores.getSelectedRow(), 0).toString());//Obtengo la codigo de la fila seleecionada
            if (nombre.equals("") || dir.equals("")) {
                JOptionPane.showMessageDialog(null, "No deje campos vacíos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
            } else {
                String sql = "UPDATE proveedores SET nombre='" + nombre + "',direccion='" + dir + "' WHERE codProveedor='" + codigo + "'";
                f.insertar(sql);
                
                //Borro todos los numeros del proveedor para volverlos agregar a la tabla tel_proveedor
                sql="DELETE FROM tel_proveedor WHERE codProveedor='"+codigo+"'";
                f.insertar(sql);//elimina los datos de telefono del usuario correspondiente
                //Ingreso el telefono obligatorio
                String sql2="INSERT INTO tel_proveedor VALUES('"+codigo+"','"+tfTel.getText()+"')";
                f.insertar(sql2);
                //reingreso los telefonos extras
                insertarTelExtra(codigo);
            }
            
            mostrarTabla("SELECT * FROM proveedores,tel_proveedor where proveedores.codProveedor=tel_proveedor.codProveedor and activo=1");
            jdAccion.dispose();
        }
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
        // TODO add your handling code here:
        this.tfDir.setText("");
        this.tfNom.setText("");
        this.tfTel.setText("");
    }//GEN-LAST:event_btnLimpiarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        jdAccion.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    
    
     private void insertarTelExtra(int cod){
        String sql2 = "";
       
            if(tfTel1.isVisible()){
                    if(tfTel1.getText().equals("    -    ")){//Campo telefono vacio
                        JOptionPane.showMessageDialog(null, "No debe dejar campos vacíos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
                    }else{
                        sql2="INSERT INTO tel_proveedor VALUES('"+cod+"','"+tfTel1.getText()+"')";
                        f.insertar(sql2);
                    }
                }
                if(tfTel2.isVisible()){
                    if(tfTel2.getText().equals("    -    ")){//Campo telefono vacio
                        JOptionPane.showMessageDialog(null, "No debe dejar campos vacíos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
                    }else{
                        sql2="INSERT INTO tel_proveedor VALUES('"+cod+"','"+tfTel2.getText()+"')";
                        f.insertar(sql2);
                    }
                }
                if(tfTel3.isVisible()){
                    if(tfTel3.getText().equals("    -    ")){//Campo telefono vacio
                        JOptionPane.showMessageDialog(null, "No debe dejar campos vacíos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
                    }else{
                        sql2="INSERT INTO tel_proveedor VALUES('"+cod+"','"+tfTel3.getText()+"')";
                        f.insertar(sql2);
                    }
                }
                if(tfTel4.isVisible()){
                    if(tfTel4.getText().equals("    -    ")){
                        JOptionPane.showMessageDialog(null, "No debe dejar campos vacíos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
                    }else{
                        sql2="INSERT INTO tel_proveedor VALUES('"+cod+"','"+tfTel4.getText()+"')";
                        f.insertar(sql2);
                    }
                }
                if(tfTel5.isVisible()){
                    if(tfTel5.getText().equals("    -    ")){
                        JOptionPane.showMessageDialog(null, "No debe dejar campos vacíos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
                    }else{
                        sql2="INSERT INTO tel_proveedor VALUES('"+cod+"','"+tfTel5.getText()+"')";
                        f.insertar(sql2);
                    }
                }
     }
    
     private void darBaja(){
        
        try{
            int codigo=Integer.parseInt(dt.getValueAt(tablaProveedores.getSelectedRow(), 0).toString());//Obtengo la codigo de la fila seleecionada
            String sql="UPDATE proveedores SET activo='0' WHERE codProveedor='"+codigo+"'";
            f.insertar(sql);
            
            mostrarTabla("SELECT * FROM proveedores,tel_proveedor where proveedores.codProveedor=tel_proveedor.codProveedor and activo=1");
        }catch(ArrayIndexOutOfBoundsException e){
            JOptionPane.showMessageDialog(null, "Debe elegir un proveedor");
        }
        
    }
    private void darAlta(){
       
        try{
            int codigo=Integer.parseInt(dt.getValueAt(tablaProveedores.getSelectedRow(), 0).toString());//Obtengo la codigo de la fila seleecionada
            String sql="UPDATE proveedores SET activo='1' WHERE codProveedor='"+codigo+"'";
            f.insertar(sql);
            
            mostrarTabla("SELECT * FROM proveedores,tel_proveedor where proveedores.codProveedor=tel_proveedor.codProveedor and activo=0");
        }catch(ArrayIndexOutOfBoundsException e){
            JOptionPane.showMessageDialog(null, "Debe elegir un proveedor");
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TablaProveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TablaProveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TablaProveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TablaProveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TablaProveedor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.edisoncor.gui.button.ButtonIcon btnAdd;
    private org.edisoncor.gui.button.ButtonIpod btnAtras;
    private org.edisoncor.gui.button.ButtonIpod btnCancelar;
    private org.edisoncor.gui.button.ButtonIpod btnDarAlta;
    private org.edisoncor.gui.button.ButtonIpod btnDarBaja;
    private org.edisoncor.gui.button.ButtonIcon btnElim;
    private org.edisoncor.gui.button.ButtonIpod btnGuardar;
    private org.edisoncor.gui.button.ButtonIpod btnLimpiar;
    private org.edisoncor.gui.button.ButtonIpod btnModificar;
    private org.edisoncor.gui.button.ButtonIpod btnNuevo;
    private org.edisoncor.gui.button.ButtonIpod btnVerBajas;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JDialog jdAccion;
    private org.edisoncor.gui.label.LabelMetric l1;
    private org.edisoncor.gui.label.LabelMetric l2;
    private org.edisoncor.gui.label.LabelMetric l3;
    private org.edisoncor.gui.label.LabelMetric l4;
    private org.edisoncor.gui.label.LabelMetric l5;
    private org.edisoncor.gui.label.LabelMetric labelMetric1;
    private org.edisoncor.gui.label.LabelMetric labelMetric2;
    private org.edisoncor.gui.label.LabelMetric labelMetric3;
    private org.edisoncor.gui.label.LabelMetric labelMetric4;
    private org.edisoncor.gui.label.LabelMetric labelMetric5;
    private org.edisoncor.gui.label.LabelMetric lblTitulo;
    private org.edisoncor.gui.panel.PanelCurves panelCurves1;
    private org.edisoncor.gui.panel.PanelCurves panelCurves2;
    private org.edisoncor.gui.panel.PanelRect panelRect1;
    private org.edisoncor.gui.panel.PanelRect panelRect2;
    private org.edisoncor.gui.panel.PanelRect panelRect3;
    private org.edisoncor.gui.panel.PanelRect panelRect4;
    private org.edisoncor.gui.panel.PanelRect panelRect5;
    private org.edisoncor.gui.panel.PanelRound panelRound1;
    private org.jdesktop.swingx.JXTable tablaProveedores;
    private java.awt.TextField tfBuscar;
    private org.edisoncor.gui.textField.TextFieldRectBackground tfDir;
    private org.edisoncor.gui.textField.TextFieldRectBackground tfNom;
    private javax.swing.JFormattedTextField tfTel;
    private javax.swing.JFormattedTextField tfTel1;
    private javax.swing.JFormattedTextField tfTel2;
    private javax.swing.JFormattedTextField tfTel3;
    private javax.swing.JFormattedTextField tfTel4;
    private javax.swing.JFormattedTextField tfTel5;
    // End of variables declaration//GEN-END:variables
}
